/**
* -------------------------------------------------------------
* @author  cl
* @date: 2022-01-04 11:35:58
* @description:  controller
* -------------------------------------------------------------
* @version 1.0.0
* @Copyright (c) 中科星图-版权所有
*/
package com.geovis.boot.service.demo.order.controller;

import com.geovis.boot.common.util.PageUtil;
import com.geovis.boot.common.util.ResultUtil;
import com.geovis.boot.common.vo.DefaultPageVO;
import com.geovis.boot.common.dto.Result;
import com.geovis.boot.service.demo.order.entity.OrderBind;
import com.geovis.boot.service.demo.order.service.IOrderBindService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@Api(description = "管理接口")
@RequestMapping("/orderBind")
public class OrderBindController {

    @Autowired
    private IOrderBindService iOrderBindService;

    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "通过id获取")
    public Result<OrderBind> get(@PathVariable Long id){

        OrderBind orderBind = iOrderBindService.getById(id);
        return new ResultUtil<OrderBind>().setData(orderBind);
    }

    @RequestMapping(value = "/getAll", method = RequestMethod.GET)
    @ApiOperation(value = "获取全部数据")
    public Result<List<OrderBind>> getAll(){

        List<OrderBind> list = iOrderBindService.list();
        return new ResultUtil<List<OrderBind>>().setData(list);
    }

    @RequestMapping(value = "/getByPage", method = RequestMethod.GET)
    @ApiOperation(value = "分页获取")
    public Result<IPage<OrderBind>> getByPage(@ModelAttribute DefaultPageVO pageVO){

        IPage<OrderBind> data = iOrderBindService.page(PageUtil.initMpPage(pageVO));
        return new ResultUtil<IPage<OrderBind>>().setData(data);
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "编辑")
    public Result<OrderBind> save(@ModelAttribute OrderBind orderBind){

        if(iOrderBindService.save(orderBind)){
            return new ResultUtil<OrderBind>().setData(orderBind);
        }
        return new ResultUtil<OrderBind>().setErrorMsg("操作失败");
    }

    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    @ApiOperation(value = "更新数据")
    public Result<OrderBind> updateById(@ModelAttribute OrderBind orderBind){

        if(iOrderBindService.updateById(orderBind)){
            return new ResultUtil<OrderBind>().setData(orderBind);
        }
        return new ResultUtil<OrderBind>().setErrorMsg("操作失败");
    }

    @RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)
    @ApiOperation(value = "编辑或更新数据")
    public Result<OrderBind> saveOrUpdate(@ModelAttribute OrderBind orderBind){

        if(iOrderBindService.saveOrUpdate(orderBind)){
            return new ResultUtil<OrderBind>().setData(orderBind);
        }
        return new ResultUtil<OrderBind>().setErrorMsg("操作失败");
    }

    @RequestMapping(value = "/delById/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "通过id删除")
    public Result<Object> delById(@PathVariable Long id){

        iOrderBindService.removeById(id);
        return new ResultUtil<Object>().setSuccessMsg("通过id删除数据成功");
    }

    @RequestMapping(value = "/delByIds/{ids}", method = RequestMethod.DELETE)
    @ApiOperation(value = "批量通过id删除")
    public Result<Object> delAllByIds(@PathVariable Long[] ids){

        for(Long id : ids){
            iOrderBindService.removeById(id);
        }
        return new ResultUtil<Object>().setSuccessMsg("批量通过id删除数据成功");
    }
}
